<extend name="Base/common" />
<block name="body">
<style type="text/css">
.money {
	width: 50px;
}
.specTable .param {
	display: none;
}
.specTable p {
	display: block;
	line-height: 50px;
}
.text-center {
	text-align: center;
}
.check-tips {
	color: #aaa;
	margin-left: 50px
}
</style>
<!-- 标签页导航 -->

<div class="span9 page_message">
  <section id="contents"> <include file="Addons/_nav" />
    <div class="tab-content"> 
      <!-- 表单 -->
      <php> $post_url || $post_url = U('edit?model='.$model['id'], $get_param);</php>
      <form class="form-horizontal form-center" method="post" action="{$post_url}" id="form">
        <div class="form-item cf toggle-title">
          <label class="item-label"> <span class="need_flag">*</span> 活动名称 <span class="check-tips"> </span></label>
          <div class="controls">
            <input type="text" value="{$data.title}" name="title" class="text" placeholder="请填写活动名称">
          </div>
        </div>
        <div class="form-item cf toggle-status">
          <label class="item-label"> 是否开启 <span class="check-tips"> </span></label>
          <div class="controls">
            <div class="check-item">
              <input type="radio" name="status" id="status_1" value="1" class="regular-radio status" <if condition="$data[status]==1">checked="checked"</if> >
              <label for="status_1"></label>
              开启 </div>          
            <div class="check-item">
              <input type="radio" name="status" id="status_0" value="0" class="regular-radio status" <if condition="intval($data[status])==0">checked="checked"</if> >
              <label for="status_0"></label>
              禁用 </div>
          </div>
        </div>           
<!--        <div class="form-item cf">
            <label class="item-label"> <span class="need_flag">*</span> 活动背景图 <span class="check-tips">建议上传640*1008规格的图片,不传将使用默认图片</span></label>
            <div class="controls uploadrow2" data-max="1" title="点击修改图片" rel="cover_id">
              <input type="file" id="upload_picture_cover_id">
              <input type="hidden" name="cover_id" id="cover_id_cover_id" value="{$data[cover_id]}"/>
              <div class="upload-img-box">
                <notempty name="data[cover_id]">
                  <div class="upload-pre-item2"><img width="100" height="100" src="{$data[cover_id]|get_cover_url}"/></div>
                  <em class="edit_img_icon">&nbsp;</em>
                </notempty>
              </div>
            </div>
        </div> -->
        <div class="form-item cf">
          <label class="item-label"> <span class="need_flag">*</span> 大礼包个数限制 <span class="check-tips">为空时表示不限制，超过此限制，系统会提示“礼包已被抢完!”，注意：此处仅控制大礼包最后兑现领取数量，但是小礼包数量是不可控的，具体领取数量和参与人数有关 </span></label>
          <div class="controls">
            <input type="number" value="{$data.prize_num|default=100}" name="prize_num" class="text" placeholder="大礼包数量">
          </div>
        </div>   
        <div class="form-item cf toggle-start_time">
          <label class="item-label"> <span class="need_flag">*</span> 有效期 <span class="check-tips"> </span></label>
          <div class="controls">
            <input type="datetime" placeholder="请选择生效时间" value="{$data.start_time|time_format}" class="text time" name="start_time">
            -
            <input type="datetime" placeholder="请选择过期时间" value="{$data.end_time|time_format}" class="text time" name="end_time">
          </div>
        </div>  
        <div class="form-item cf">
          <label class="item-label"> <span class="need_flag">*</span> 大礼包 <span class="check-tips"> 分享者达到分享目标就可以获得的奖品</span></label>
          <div class="controls">
            <input type="text" value="{$data.prize_title}" name="prize_title" class="text" placeholder="请填写大礼包名称">
          </div>
        </div>
        <div class="form-item cf mt_10 mb_10">
          <label class="item-label"> <span class="need_flag">*</span> 大礼包需要
            <input style="vertical-align:0" type="number" value="{$data.limit_num|default=5}" name="limit_num" class="text money"> 位好友帮拆开才可用 </label>
        </div>            

        <div class="form-item cf">
          <label class="item-label"> <span class="need_flag">*</span> 大礼包图标 <span class="check-tips"> </span></label>
          <div class="controls uploadrow2" data-max="1" title="点击修改图片" rel="prize_cover_id">
              <input type="file" id="upload_picture_prize_cover_id">
              <input type="hidden" name="prize_cover_id" id="cover_id_prize_cover_id" value="{$data[prize_cover_id]}"/>
              <div class="upload-img-box">
                <notempty name="data[prize_cover_id]">
                  <div class="upload-pre-item2"><img width="100" height="100" src="{$data[prize_cover_id]|get_cover_url}"/></div>
                  <em class="edit_img_icon">&nbsp;</em>
                </notempty>
              </div>
            </div>
        </div>   
        <div class="form-item cf">
          <label class="item-label"> <span class="need_flag">*</span> 小礼包 <span class="check-tips"> 帮拆后好友可以获得的奖品</span></label>
          <div class="controls">
            <input type="text" value="{$data.prize2_title}" name="prize2_title" class="text" placeholder="请填写小礼包名称">
          </div>
        </div>           
        <div class="form-item cf">
          <label class="item-label"> <span class="need_flag">*</span> 小礼包发放数量 <span class="check-tips"> 为空时表示不限制</span></label>
          <div class="controls">
            <input type="number" value="{$data.prize2_num}" name="prize2_num" class="text" placeholder="小礼包数量">
          </div>
        </div>   
        <div class="form-item cf">
          <label class="item-label"> <span class="need_flag">*</span> 小礼包图标 <span class="check-tips"> </span></label>
          <div class="controls uploadrow2" data-max="1" title="点击修改图片" rel="prize2_cover_id">
              <input type="file" id="upload_picture_prize2_cover_id">
              <input type="hidden" name="prize2_cover_id" id="cover_id_prize2_cover_id" value="{$data[prize2_cover_id]}"/>
              <div class="upload-img-box">
                <notempty name="data[prize2_cover_id]">
                  <div class="upload-pre-item2"><img width="100" height="100" src="{$data[prize2_cover_id]|get_cover_url}"/></div>
                  <em class="edit_img_icon">&nbsp;</em>
                </notempty>
              </div>
            </div>
        </div>              
        <!--<div class="form-item cf">
          <label class="item-label"> <span class="need_flag">*</span>奖品核销密码 <span class="check-tips">默认为123456</span></label>
          <div class="controls">
            <input type="text" value="{$data.pay_password|default=123456}" name="pay_password" class="text" placeholder="请填写奖品核销密码">
          </div>
        </div>-->               
        <div class="form-item cf toggle-is_all_shops">
          <label class="item-label"> 适用门店 <span class="check-tips"> </span></label>
          <div class="controls">
            <div class="check-item">
              <input type="radio" name="is_all_shops" id="is_all_shops_0" value="0" class="regular-radio is_all_shops" <if condition="intval($data[is_all_shops])==0">checked="checked"</if> >
              <label for="is_all_shops_0"></label>
              全部门店参与 </div>
            <div class="check-item">
              <input type="radio" name="is_all_shops" id="is_all_shops_1" value="1" class="regular-radio is_all_shops" <if condition="$data[is_all_shops]==1">checked="checked"</if> >
              <label for="is_all_shops_1"></label>
              指定门店参与 </div>
          </div>
        </div>        
        <div class="form-item cf" id="shops_item">
        <div style="margin:15px 0;" class="data-table">
            <table cellspacing="1" cellpadding="0">
              <thead>
                <tr>
                  <th>门店名</th>
                  <th>详细地址</th>
                  <th>操作</th>
                </tr>
              </thead>
              <tbody id="shops_list">
              <volist name="shops_list" id="gl">
                <tr rel="{$gl.id}" class="shops_data">
								  <td>{$gl.name}</td>
								  <td>{$gl.address}</td>
								  <td>
								  <input type="hidden" name="shop_ids[]" value="{$gl.id}" />
								  <a href="javascript:void(0);" onclick="remove_tr(this)">删除</a></td>                 
								  </tr>
                 </volist>
                <tr class="add_shops_tr">
                  <td colspan="3"><a href="javascript:choose_shops()">+增加门店</a></td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
        <div class="form-item cf">
          <label class="item-label"> 分享介绍 <span class="check-tips">分享给好友时显示的活动介绍 </span></label>
          <div class="controls">
            <label class="textarea input-large">
            <textarea name="intro">{$data[intro]}</textarea>
            </label>
          </div>
        </div>        
        <div class="form-item cf">
          <label class="item-label">活动规则 <span class="check-tips"> </span></label>
          <div class="controls">
              <label class="textarea">
              <textarea name="content" style="width:405px; height:100px;">{$data[content]}</textarea>
              {:hook('adminArticleEdit', array('name'=>'content','value'=>$data[content]))} </label>          
          </div>
        </div>        
        <div class="form-item form_bh">
          <notempty name="data.id">
            <input type="hidden" name="id" value="{$data.id}">
          </notempty>
          <button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">{$submit_name|default='确 定'}</button>
        </div>
      </form>
           
    </div>
  </section>
</div>
</block>
<block name="script">
  <link href="__STATIC__/datetimepicker/css/datetimepicker.css?v={:SITE_VERSION}" rel="stylesheet" type="text/css">
  <php> if(C('COLOR_STYLE')=='blue_color') echo '
    <link href="__STATIC__/datetimepicker/css/datetimepicker_blue.css?v={:SITE_VERSION}" rel="stylesheet" type="text/css">
    '; </php>
  <link href="__STATIC__/datetimepicker/css/dropdown.css?v={:SITE_VERSION}" rel="stylesheet" type="text/css">
  <script type="text/javascript" src="__STATIC__/datetimepicker/js/bootstrap-datetimepicker.min.js"></script> 
  <script type="text/javascript" src="__STATIC__/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js?v={:SITE_VERSION}" charset="UTF-8"></script> 
  <script type="text/javascript">
function add_tr(){
	var count = 0;
	$('.list_tr').each(function() {
        count += 1;
    });	
	
	re = new RegExp("sort_id", "g");
	str  = $('#default_tr').html().replace(re, count+1);
	console.log(str);
	var html = '<tr class="list_tr">'+ str +'</tr>';
	$('.list_tr:last').after(html);
	
	if(count>=4){
	    $('.more_tr').hide();	
	}
}
function remove_tr(_this){	
	$(_this).parent().parent().remove();
	
	var count = 0;
	$('.td_key').each(function() {
		count = count + 1;
        if(count>1) $(this).html(count);
    });	
}
function is_all_shops(){
	var val = $('input[name="is_all_shops"]:checked').val();
	if(val==0){
		$('#shops_item').hide();
		$('.shops_data').each(function(index, element) {
            $(this).remove();
        });
	}else{
		$('#shops_item').show();
	}
}
function choose_shops(){
	var dataUrl = "{:addons_url('Coupon://Shop/lists', array('isAjax'=>1))}";

	$.WeiPHP.openSelectShops(dataUrl,function(shopsList){
				if(shopsList.length>0){
					//获取已经存在的门店
					var arr = [];
					var shops_count = 0;
					$('.shops_data').each(function(){
						var gid = $(this).attr('rel');
						arr.push(gid);
						shops_count = shops_count + 1;
					});
					
					for(var i=0;i<shopsList.length;i++){
						var val = shopsList[i];
						
						if($.inArray(val.id, arr)!=-1) continue;
												
						var html =  '<tr rel="'+val.id+'" class="shops_data">'
								  + '<td>'+val.name+'</td>'
								  + '<td>'+val.address+'</td>'
								  + '<td>'
								  + '<input type="hidden" name="shop_ids[]" value="'+val.id+'" />'
								  + '<a href="javascript:void(0);" onclick="remove_tr(this)">删除</a></td> '                 
								  + '</tr>';
								  
				        $('.add_shops_tr').before(html);
					}
				}
			});
}
$(function(){    
	initUploadImg();
	initUploadFile();
    $('.time').datetimepicker({
        format: 'yyyy-mm-dd hh:ii',
        language:"zh-CN",
        minView:0,
        autoclose:true
    });
    $('.date').datetimepicker({
        format: 'yyyy-mm-dd',
        language:"zh-CN",
        minView:2,
        autoclose:true
    });	
    showTab();
	
	$('.toggle-data').each(function(){
		var data = $(this).attr('toggle-data');
		if(data=='') return true;		
		
	     if($(this).is(":selected") || $(this).is(":checked")){
			 change_event(this)
		 }
	});
	
	$('.toggle-data').bind("click",function(){ change_event(this) });
	
	$('.is_all_shops').bind('click',function(){ is_all_shops();	});
	is_all_shops();
});
</script> 
</block>
